<?php
namespace App\Services;

use Redis;
class RedisService
{
    private static $redis;

    /**
     * @return Redis
     */
    public static function getRedis() : Redis
    {
        if (self::$redis === null) {
            self::setRedis();
        }
        return self::$redis;
    }

    private static function setRedis()
    {
        $redis = new Redis();
        $redis->connect(env('REDIS_HOST'), env('REDIS_PORT'));
        $redis->select(0);
        self::$redis = $redis;
    }
}